import { listSubjectData, listSysSymbols } from '@/api/yzt'
const eswyzt = {
  namespaced: true,
  state: {
    map: undefined,
    mapService: undefined,
    currentSearchLayer: undefined,
    attributeTable: undefined,
    attributeTableData: [],
    symbols: undefined,
    drawControl: undefined,
    showLayerLegend: undefined,
    showLayerStatics: false,
    /**
     * 地图切换索引
     */
    mapModuleIndex: 0,
    /**
     * 二维地图联动参数
     */
    extentChangeSourceMap: {},
    /**
     * 三维地图联动参数
     */
    extentChangeSourceScene: {},
    /**
     * 三维视图对象
     */
    sceneViewer: null,
    /**
     * 三维工具类
     */
    sceneTool: null,
     /**
     * 双屏对比
     */
    comparable: undefined
  },

  mutations: {
    setMap: (state, map) => {
      state.map = map
    },
    setMapService: (state, mapservice) => {
      state.mapService = mapservice
    },
    setCurrentSearchLayer: (state, currentSearchLayer) => {
      state.currentSearchLayer = currentSearchLayer
    },
    setAttributeTable: (state, isTrue) => {
      state.attributeTable = isTrue
    },
    setAttributeTableData: (state, data) => {
      state.attributeTableData = data
    },
    setSymbols: (state, s) => {
      state.symbols = s
    },
    setDrawControl: (state, draw) => {
      state.drawControl = draw
    },
    setShowLayerLegend: (state, isTrue) => {
      state.showLayerLegend = isTrue
    },
    setShowLayerStatics: (state, isTrue) => {
      state.showLayerStatics = isTrue
    },
    /**
     * 设置地图切换索引
     * @param state
     * @param index
     */
    setSwitchMapModuleIndex: (state, index) => {
      state.mapModuleIndex = index
    },
    /**
     * 设置二维地图联动参数
     * @param state
     * @param source
     */
    setExtentChangeSourceMap: (state, source) => {
      state.extentChangeSourceMap = source
    },
    /**
     * 设置三维地图联动参数
     * @param state
     * @param source
     */
    setExtentChangeSourceScene: (state, source) => {
      state.extentChangeSourceScene = source
    },
    setSceneViewer: (state, viewer) => {
      state.sceneViewer = viewer
    },
    setSceneTool: (state, toll) => {
      state.sceneTool = toll
    },


    setMeasureSync: (state, m) => {
      state.measureSync = m;
    },
    setComparable: (state, c) => {
      state.comparable = c;
    },
    SET_ASPECT:(state,aspect)=>{
      state.aspect = aspect;
    }


  },

  actions: {
    /**
     * 图层查询属性
     * @param commit
     * @param state
     * @returns {Promise<any>}
     * @constructor
     */
    QueryLayerAttributes({ commit, state }, param) {
      return new Promise((resolve, reject) => {
        state.mapService.queryLayerAttribute(param.layer, param.start, param.size, param.sql ? param.sql : '1=1').then(res => {
          const features = res.result.recordsets[0].features.features
          commit('setAttributeTableData', features)
          resolve({ data: features, total: res.result.totalCount })
        }).catch(e => {
          reject(e)
        })
      })
    },
    /**
     * 请求系统符号库
     * @param commit
     * @param state
     * @param param
     * @returns {Promise<any>}
     * @constructor
     */
    RequestSysSymbols({ commit, state }, param) {
      return new Promise((resolve, reject) => {
        listSysSymbols().then(res => {
          commit('setSymbols', res.data)
          resolve(res.data)
        }).catch(e => {
          reject(e)
        })
      })
    }
  }

}

export default eswyzt
